<template>
	<view class="content">
		<view class="wid100 dis foSi30 fowe600" style="height: 100rpx;">
			<view class="wid33 hei100 dis disJuC bacFFF" @click="xuan(0)">
				<view
					:style="orIndex == 0?'height: 96rpx;border-bottom: 4rpx solid #035DFF;color: #035DFF;':'height: 96rpx;border-bottom: 4rpx solid #fff;color: #000;'"
					class="dis disAl">全部</view>
			</view>
			<view class="wid33 hei100 dis disJuC bacFFF" @click="xuan(1)">
				<view
					:style="orIndex == 1?'height: 96rpx;border-bottom: 4rpx solid #035DFF;color: #035DFF;':'height: 96rpx;border-bottom: 4rpx solid #fff;color: #000;'"
					class="dis disAl">待支付</view>
			</view>
			<view class="wid33 hei100 dis disJuC bacFFF" @click="xuan(2)">
				<view
					:style="orIndex == 2?'height: 96rpx;border-bottom: 4rpx solid #035DFF;color: #035DFF;':'height: 96rpx;border-bottom: 4rpx solid #fff;color: #000;'"
					class="dis disAl">已完成</view>
			</view>
			<view class="wid33 hei100 dis disJuC bacFFF" @click="xuan(3)">
				<view
					:style="orIndex == 3?'height: 96rpx;border-bottom: 4rpx solid #035DFF;color: #035DFF;':'height: 96rpx;border-bottom: 4rpx solid #fff;color: #000;'"
					class="dis disAl">已过期</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 100rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view style="height: 30rpx;"></view>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid100 bacFFF mar-bott30" @click="xiang(item)" style="padding: 20rpx 0;">
					<view class="wid90 mar">
						<view class="dis disAl disJuB foSi25">
							<view style="color: #5B5B5B;">订单号：{{item.ordernum}}</view>
							<view v-if="item.status == 0" style="color: #FF0000;">待付款</view>
							<view v-if="item.status == 1">已完成</view>
							<view v-if="item.status == 2" style="color: #868686;">已退款</view>
							<view v-if="item.status == 3" style="color: #868686;">已过期</view>
						</view>
						<view class="mar-top30 dis">
							<view style="width: 60rpx;">
								<image src="../../static/jiayou.png" style="width: 35rpx;height: 36rpx;"></image>
							</view>
							<view class="foSi35 fowe600">{{item.gasstation.name}}</view>
						</view>
						<view class="dis " style="margin-top: 25rpx;">
							<view style="width: 60rpx;"></view>
							<view class="foSi25" style="color: #5B5B5B;">{{item.oil_type}}丨{{item.createtime}}</view>
						</view>
						<view class="dis " style="margin-top: 53rpx;">
							<view style="width: 60rpx;"></view>
							<view class="dis disAl disJuB wid90">
								<view class="foSi25 fowe600" style="vertical-align: bottom;">
									<span>¥</span>
									<span class="foSi40">{{Number(item.pay_amount).toFixed(2)}}</span>
								</view>
								<!-- <view v-if="item.status == 0" class="dis disAl disJuC foSi20 borRad40"
									@click.stop="zhufu(item)"
									style="width: 132rpx;height: 43rpx;border: 1rpx solid #FF0000;color: #FF0000;">立即支付
								</view> -->
							</view>
						</view>
						<view class="hei20"></view>
					</view>
				</view>
			</block>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orIndex: 0,
				list: [],
				last_page: 0,
				page: 1,
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {},
		methods: {
			zhufu(item) {
				let that = this
				if (that.pd) {
					return;
				}
				that.pd = true
				uni.showLoading({
					title: '支付中...'
				})
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_dzf_pay',
					method: 'POST',
					header: {
						'site-id': that.global.site_id,
						"token": uni.getStorageSync('token')
					},
					data: {
						id: item.id
					},
					success: (res) => {
						let result = res.data
						console.log(result)
						uni.requestPayment({
							timeStamp: result.timeStamp,
							nonceStr: result.nonceStr,
							package: result.package,
							signType: 'MD5',
							paySign: result.paySign,
							success: function(res) {
								console.log(res);
								uni.showModal({
									title: '提示',
									content: '支付成功',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {
											setTimeout(function(){
												that.page = 1
												that.list = []
												that.getList()
											},1000)
										}
									}
								})
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
								// 支付失败
								console.log(err)
								uni.showToast({
									title: '支付失败',
									icon: 'none',
									duration: 2000
								})
							}
						});
					},
					complete() {
						uni.hideLoading()
						that.pd = false
					}
				});
			},
			xiang(item) {
				if (item.status == 1) {
					this.tiaozhuan('/pages/order/particulars?id=' + item.id)
				}
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_order_lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						status: that.orIndex == 1 ? 0 : that.orIndex == 2 ? 1 : that.orIndex == 3?3:'',
						page: that.page,
						limit: 10,
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							that.list = that.list.concat(result.data.data)
						}
					}
				})
			},
			xuan(index) {
				if (this.orIndex != index) {
					this.orIndex = index
					this.list = []
					this.page = 1
					this.getList()
				}
			},
			lower(e) {
				if (this.last_page > this.page) {
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		background: #F8F9FD;
		min-height: 100vh;
	}
</style>